module.exports = app => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  
    const Article = app.model.define('article', {
        id: {
            type: INTEGER(20),
            primaryKey: true,
            autoIncrement: true,
          },
          cate_id: {
            type: INTEGER(20),
            allowNull: false,
            defaultValue: 0,
            comment: "分类id"
          },
          title: {
            type: STRING(30),
            allowNull: false,
            defaultValue: "",
            comment: "文章标题",
          },
          thumb: {
            type: STRING(1000),
            allowNull: true,
            defaultValue: "",
            comment: "缩略图",
          },
          keywords: {
            type: STRING(80),
            allowNull: true,
            defaultValue: "",
            comment: "关键词",
          },
          description: {
            type: STRING(255),
            allowNull: true,
            defaultValue: "",
            comment: "描述",
          },
          islink: {
            type: INTEGER(1),
            allowNull: true,
            defaultValue: 0,
            comment: "是否外链 0否 1是",
          },
          url: {
            type: STRING(255),
            allowNull: true,
            defaultValue: "",
            comment: "外链网址",
          },
          posid: {
            type: INTEGER(1),
            allowNull: true,
            defaultValue: 0,
            comment: "推荐位 1焦点 2头条 3推荐",
          },
          order: {
            type: INTEGER(60),
            allowNull: true,
            defaultValue: 0,
            comment: "排序",
          },
          status: {
            type: INTEGER(1),
            allowNull: false,
            defaultValue: 1,
            comment: "状态 0取消 1正常",
          },
          source: {
            type: STRING(50),
            allowNull: true,
            defaultValue: "",
            comment: "来源",
          },
          auther: {
            type: STRING(50),
            allowNull: true,
            defaultValue: "",
            comment: "作者",
          },
          content: {
            type: TEXT,
            allowNull: true,
            defaultValue: "",
            comment: "内容",
          },
          hits: {
            type: INTEGER(1),
            allowNull: true,
            defaultValue: 0,
            comment: "阅读量",
          },
        created_time: {
          type:DATE,
          get(){
             return app.formatTime(this.getDataValue('created_time'))
          }
        },
        updated_time: DATE,
      });
  
    // 关联关系
    Article.associate = function (models) {
        // 关联栏目
        app.model.Article.belongsTo(app.model.Category, { foreignKey: 'cate_id' });
    }
  
    return Article;
  };